import { loadUIPage, loadUIPageCur } from './api';
import { PageTypes } from './const';

export default {
    data() {
        return {
            formName: '',
        }
    },
    methods: {
        //加载单个Page
        loadUIPage(formName, pageType) {
            return loadUIPage(formName, pageType).then(res => {
                var uiTemplate = res.data || {}
                var uiPage = this.initUIPage(uiTemplate.pages && uiTemplate.pages[0]) //指定了pageType只有一条不用find. (uiTemplate.pages || []).find(p => p.pageType === PageTypes.Table)
                uiPage._tplId = uiTemplate.id
                return uiPage
            })
        },
        loadUIPageCur(formName) {
            return loadUIPageCur(formName).then(res => {
                var uiTemplate = res.data || {}
                return uiTemplate
            })
        },
        initUIPage(uiPage) {
            if (!uiPage) uiPage = {}
            if (!uiPage.ui) uiPage.ui = {}
            if (!uiPage.ui.gridCols) uiPage.ui.gridCols = []
            if (!uiPage.ui.batActions) uiPage.ui.batActions = []
            if (!uiPage.ui.rowActions) uiPage.ui.rowActions = []
            if (!uiPage.ui.rowOutActions) uiPage.ui.rowOutActions = []
            return uiPage
        }
    },
    computed: {
        searchFormPageType() {
            return (this.uiPage && this.uiPage.ui && this.uiPage.ui.searchFormPageType) || PageTypes.TableSearch
        }
    }
}
